import { Controller, Post, Body, Get } from '@nestjs/common';
import { AiInterpretationService } from './ai-interpretation.service';

@Controller('api-test')
export class ApiTestController {
  constructor(private readonly aiService: AiInterpretationService) {}

  @Post('test-deepseek')
  async testDeepSeek(@Body() body: { question?: string }) {
    try {
      // 使用乾卦作为测试
      const testHexagram = {
        id: 1,
        name: 'Qian',
        chineseName: '乾',
        symbol: '☰',
        description: '天',
        interpretation: '元亨利贞',
        lines: [
          '初九：潜龙勿用',
          '九二：见龙在田，利见大人',
          '九三：君子终日乾乾，夕惕若厉，无咎',
          '九四：或跃在渊，无咎',
          '九五：飞龙在天，利见大人',
          '上九：亢龙有悔'
        ]
      };

      const result = await this.aiService.interpretHexagram(testHexagram, body.question);
      
      return {
        success: true,
        data: {
          hexagram: testHexagram,
          question: body.question,
          interpretation: result
        }
      };
    } catch (error) {
      return {
        success: false,
        error: error.message,
        data: null
      };
    }
  }

  @Get('api-status')
  async getApiStatus() {
    return {
      deepseek: {
        configured: !!process.env.DEEPSEEK_API_KEY,
        baseUrl: process.env.DEEPSEEK_BASE_URL || 'https://api.deepseek.com/v1'
      },
      openai: {
        configured: !!process.env.OPENAI_API_KEY,
        baseUrl: process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1'
      }
    };
  }
}
